import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { SGroupInvite } from "../../../../Message/Public/SGroupInvite";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SGroupInviteEx } from "../../../../Message/Public/SGroupInviteEx";
import { CopyConfig } from "../../resource/CopyConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { SGroup } from "../../../../Message/Public/SGroup";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { SWaitingPlayer } from "../../../../Message/Public/SWaitingPlayer";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { _isInvite } from "../../../../this/_isInvite";
import { _dataObj } from "../../../../this/_dataObj";
//class GroupRequestRenderer
    
    export  class GroupRequestRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._campTxt = ObjCreate.createTextField("", 0, 0, 30, 20, this);
            this._campTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._playerTxt = ObjCreate.createTextField("", 30, 0, 150, 20, this);
            this._playerTxt.addEventListener(flash.events.TextEvent.LINK, this.onPlayerTxtClickHandler);
            this._requestTxt = ObjCreate.createTextField("", 0, 30, 200, 20, this);
            this._requestTxt.addEventListener(flash.events.TextEvent.LINK, this.onRequestTxtClickHandler);
            this._okBtn = ObjCreate.createGButton(Language.getString(69903), 200, 10, 35, 25, this);
            this._okBtn.name = "ok";
            this._okBtn.drawNow();
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            ObjCreate.createBg(0, 55, this.width, 2, this, ImagesConst.SplitLine);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            super.data = arg1;
            this._dataObj = arg1["data"];
            this._isInvite = arg1["isInvite"];
            this._isCross = arg1["isCross"];
            if (this._isCross) 
            {
                loc1 = Language.getString(62313);
                loc2 = Language.getString(62314);
            }
            else 
            {
                loc1 = Language.getString(62040);
                loc2 = Language.getString(62041);
            }
            if (typeof this._dataObj === "sgroupinvite") 
            {
                loc3 = this._dataObj as SGroupInvite;
                this._miniPlayer = loc3.player;
                if (this._isInvite) 
                {
                    this._requestTxt.htmlText = HTMLUtil.addColor(loc1, "#ffffff");
                }
                else 
                {
                    this._requestTxt.htmlText = HTMLUtil.addColor(loc2, "#ffffff");
                }
            }
            else if (typeof this._dataObj === "sgroupinviteex") 
            {
                loc4 = this._dataObj as SGroupInviteEx;
                this._miniPlayer = this.getCaptain(loc4.groupInfo);
                if (loc4.copyCode != 0) 
                {
                    loc5 = CopyConfig.instance.getInfoByCode(loc4.copyCode);
                    this._requestTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(62042, loc5.name), "#ffffff");
                }
                else 
                {
                    this._requestTxt.htmlText = HTMLUtil.addColor(loc1, "#ffffff");
                }
            }
            this._campColor = ColorConfig.instance.getCampColor(this._miniPlayer.camp).color;
            this._campName = GameDefConfig.instance.getCampShort(this._miniPlayer.camp).name + "•";
            this._campTxt.htmlText = HTMLUtil.addColor(this._campName, this._campColor);
            this._playerTxt.htmlText = HTMLUtil.addColor("<a href=\'event: 0\'><u>" + this._miniPlayer.name + "</u></a>", "#ffffff") + HTMLUtil.addColor("（" + this._miniPlayer.level + Language.getString(62037) + "）", "#F1FFB1");
            this._playerTxt.x = this._campTxt.width;
            return;
        }

        /* internal  */getCaptain(arg1: SGroup): SPublicMiniPlayer
        {
            var loc1=0;
            while (loc1 < arg1.players.length) 
            {
                if (EntityUtil.equal(arg1.captainId, (arg1.players[loc1] as SWaitingPlayer).miniPlayer.entityId)) 
                {
                    return (arg1.players[loc1] as SWaitingPlayer).miniPlayer;
                }
                ++loc1;
            }
            return null;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._dataObj) 
            {
                loc1 = (arg1.target as GButton).name;
                if (loc1 == "ok") 
                {
                    if (this._isCross) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_Agree, {"isInvite": _isInvite, "data": _dataObj}));
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Group_Agree, {"isInvite": _isInvite, "data": _dataObj}));
                    }
                }
            }
            return;
        }

        /* internal  */onPlayerTxtClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._miniPlayer) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerInfo_view, this._miniPlayer.entityId));
            }
            return;
        }

        /* internal  */onRequestTxtClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            return;
        }

        /* internal */ /* var */_campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_requestTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_dataObj: Object;

        /* internal */ /* var */_isInvite: Boolean;

        /* internal */ /* var */_campColor: string;

        /* internal */ /* var */_campName: string;

        /* internal */ /* var */_miniPlayer: SPublicMiniPlayer;

        /* internal */ /* var */_isCross: Boolean;
    }
